<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use Spatie\Permission\Models\Role;
use App\Models\User;
use App\Models\Item;
use Route;


class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
/*        $user = Redis::get('name');
        dd($user);*/
        $this->middleware('auth');
    }
    public function app()
    {
        return view('api.index');
    }
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        /*$name = Route::currentRouteName();
        $action = Route::currentRouteAction();
        var_dump($name);
        dd($action);*/
        //\App\Models\Order::firstOrCreate(['name'=>8888]);
       /* $order=\App\Models\Order::find(2);
        $order->name="777777";
        $order->save();*/
       /* $order= new \App\Models\Order;
        $order->name="666";
        $order->save();*/
       /* $item=new Item;
        $item->name=666;
        dd($item->save());*/
       /* dd(\DB::table('items')->insertGetId(['name'=>888]));
        dd(Item::firstOrCreate(['name'=>12345],['num'=>1,'status'=>1]));
        //\DB::table('items')->increment('num',2);
        \DB::table('items')->decrement('num',2);*/
        /*Auth::user()->assignRole('admin');*/
       /* $info=User::find(1)->getRoleNames();
        //Role::findByName('admin')->delete();
        //Auth::user()->removeRole('admin');
        Auth::user()->assignRole('admin');*/
        /*$permissions = Auth::user()->getAllPermissions()->toArray();
        dd($permissions);*/
                // create permissions
  /*      Permission::create(['name' => 'edit articles']);
        Permission::create(['name' => 'delete articles']);
        Permission::create(['name' => 'publish articles']);
        Permission::create(['name' => 'unpublish articles']);

        // create roles and assign existing permissions
        $role = Role::create(['name' => 'writer']);
        $role->givePermissionTo('edit articles');*/
               /*$role = Role::create(['name' => 'admin']);
        $role->givePermissionTo('publish articles');
        $role->givePermissionTo('unpublish articles');*/
        //$root = Category::create(['name' => 'The Root of All Evil']);
        //$root = Category::find(2);
        /*dd($root->getAncestors()); */
        /*dd($root->getSiblings()); */
        //dd($root->getDescendants()->toArray());
         //dd($root->getDescendants()); 
        //dd($root->getImmediateDescendants());
        /*$nodes=DB::select('SELECT * from categories WHERE lft>:lft AND lft<:rgt',['lft'=> $root->lft,'rgt'=>$root->rgt]);*/
        /*$nodes=Category::find(5);
        $tar_node= Category::find(3);
        $tar_node->moveToRightOf($nodes);*/
       /* $nodes= Category::where('lft','>',$root->lft)->where('rgt','<',$root->rgt)->all();*
        dd($nodes);*/
        /*$monsters = new Category(['name' => 'Horrible Monsters']);
        $monsters->save();

        $monsters->makeSiblingOf($dragons);*/
       /* $dragons = Category::create(['name' => 'Here Be Dragons2_']);
        $dragons->makeChildOf($root);
*/
        //exit;
      /*  echo date('Y-m-d H:i:s',time());
        event(new SomeEvent(Auth::user()));exit;*/
        return view('home');
    }
}
